<template>
  <div>
    <div class="p-3 text-grey">登录</div>
    <cell-group>
      <field title="请输入6位数字" v-model="mobile" placeholder="手机号" type="tel">
        <i slot="label" class="iconfont text-grey font-2x icon-phone"></i>
      </field>
      <field title="请确认6位数字" v-model="password" placeholder="密码" type="password">
        <i slot="label" class="iconfont text-grey font-2x icon-lock"></i>
      </field>
    </cell-group>
    <div style="padding:15px;">
      <btn class="btn-block" @click="login" type="primary">登录</btn>
    </div>
  </div>
</template>

<script>
import { Button, Cell, CellGroup, Field, Toast } from 'vant'
import http from '../http'

export default {
  components: {CellGroup, Field, Cell, Btn: Button},
  name: 'login',
  data: () => ({
    mobile: '18927543078',
    password: '111111'
  }),
  methods: {
    login () {
      http.post('/user/mobileLogin', this.$data).then(subject => {
        this.$store.commit('login', subject)
        var from = this.$route.query.from
        if (from) {
          Toast('登录成功, 为您转到登录前页面')
          this.$router.replace(from)
        } else {
          Toast.success('登录成功')
          this.$router.replace('/')
        }
      })
    }
  }
}
</script>
